﻿using Core.Domain.Entities;
using Core.IocHelpers;

namespace Core.Settings
{
  ///<summary>Settings</summary>
  /// <remarks>Stored in App settings in registry?</remarks>
  [AutoRegister]
  public class CurrentEnvironment : IEnvironment
  {
    private static Community _community;
    private static BallotEntryComputer _computer;
    private static Election _election;
    private static VotingLocation _location;
    private static Teller _teller;
    private static IAppSettings AppSettings;

    public CurrentEnvironment()
    {
      AppSettings = IoC.Container.Resolve<IAppSettings>();
    }

    #region IEnvironment Members

    public VotingLocation Location
    {
      get { return _location; }
      set
      {
        _location = value;
        if (value != null)
          AppSettings.LocationId = value.Id;
      }
    }

    public Teller Teller
    {
      get { return _teller; }
      set
      {
        _teller = value;
        if (value != null)
          AppSettings.TellerId = value.Id;
      }
    }

    public Election Election
    {
      get { return _election; }
      set
      {
        _election = value;
        if (value != null)
          AppSettings.ElectionId = value.Id;
      }
    }

    public Community Community
    {
      get { return _community; }
      set
      {
        _community = value;
        if (value != null)
          AppSettings.CommunityId = value.Id;
      }
    }

    public BallotEntryComputer Computer
    {
      get { return _computer; }
      set
      {
        _computer = value;
        if (value != null)
          AppSettings.ComputerId = value.Id;
      }
    }

    #endregion
  }
}